package de.fhb.formel1.dbhibernate.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

/**
 * TODO documentation
 */
public class HibernateUtil {

    private static SessionFactory sessionFactory;
    
    static {
        try {
            sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            
            throw new ExceptionInInitializerError(ex);
        }
    }
    
    
    public static SessionFactory getSessionFactory() {
//          Alternatively, you could look up in JNDI here
        return sessionFactory;
    }
    
    
    public static void shutdown() {
//          Close caches and connection pools
        getSessionFactory().close();
    }
}
